package assignment10;

import java.io.*;
public class FileClass {
	public static void main(String[] args) {
		File Dir = new File("G:\\Users\\IOtest");
		String filename = "FileTest.txt";
		File file =  new File(Dir, filename);
		if(!file.exists()) {
			try {
				file.createNewFile();				
			} catch (Exception e) {
				// TODO: handle exception
				System.out.println(e.getMessage());
			}
		}
		if(file.canWrite()) {
			try {
				BufferedWriter writer = new BufferedWriter(new FileWriter(file.getAbsolutePath()));
				writer.write("哈哈哈憨批");
				writer.newLine();
				writer.write("End Line");
				writer.close();
				System.out.println("File "+file.getAbsolutePath()+" Write successed");
			} catch (Exception e) {
				// TODO: handle exception
				System.out.println(e.getMessage());
			}
		}
		else {
			System.out.println("File "+file.getName()+" Can not write");
		}
	}
}
